package com.pzb.web.controller.page;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pzb.common.annotation.Log;
import com.pzb.common.core.controller.BaseController;
import com.pzb.common.core.domain.AjaxResult;
import com.pzb.common.enums.BusinessType;
import com.pzb.page.domain.PgPageItem;
import com.pzb.page.service.IPgPageItemService;

/**
 * 页面模块Controller
 * 
 * @author pzb
 * @date 2021-09-25
 */
@RestController
@RequestMapping("/page/item")
public class PgPageItemController extends BaseController
{
    @Autowired
    private IPgPageItemService pgPageItemService;

    /**
     * 查询页面模块列表
     */
    @GetMapping("/list")
    public AjaxResult list(PgPageItem pgPageItem)
    {
        List<PgPageItem> list = pgPageItemService.selectPgPageItemList(pgPageItem);
        return AjaxResult.success(list);
    }

    /**
     * 获取页面模块详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pgPageItemService.selectPgPageItemById(id));
    }

    /**
     * 新增页面模块
     */
    @Log(title = "页面模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PgPageItem pgPageItem)
    {
        return toAjax(pgPageItemService.insertPgPageItem(pgPageItem));
    }

    /**
     * 修改页面模块
     */
    @PreAuthorize("@ss.hasPermi('page:item:edit')")
    @Log(title = "页面模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PgPageItem pgPageItem)
    {
        return toAjax(pgPageItemService.updatePgPageItem(pgPageItem));
    }

    /**
     * 上移
     */
    @PostMapping("/moveUp")
    public AjaxResult moveUp(@RequestBody PgPageItem pgPageItem)
    {
        return toAjax(pgPageItemService.moveUp(pgPageItem));
    }
    /**
     * 下移
     */
    @PostMapping("/moveDown")
    public AjaxResult moveDown(@RequestBody PgPageItem pgPageItem)
    {
        return toAjax(pgPageItemService.moveDown(pgPageItem));
    }

    /**
     * 删除页面模块
     */
    @PreAuthorize("@ss.hasPermi('page:item:remove')")
    @Log(title = "页面模块", businessType = BusinessType.DELETE)
	@DeleteMapping
    public AjaxResult remove(@RequestBody PgPageItem pgPageItem)
    {
        return toAjax(pgPageItemService.deletePgPageItem(pgPageItem));
    }
}
